*********************************************************************
* Part of the replication files for:

* Are Foreign Firms Good for the Environment? FDI and Protected Areas
* Ana Carolina Garriga and Muzhou Zhang

* See 0-README.txt for more information
*********************************************************************



/// StataIC 15.1
/// Mac Studio 2022 with Apple M1 Max chip on macOS 15.3 (24D60)
/// Last updated on Feb 14, 2025



clear all

cd "~/Replication-Garriga-Zhang-II" /// CHANGE PATH TO WHERE THE FOLDER IS LOCATED IN YOUR MACHINE



*******************
* 1 MAIN ANALYSIS *
*******************

use "1-data.dta", clear

xtset country year

global X c.gdppc##c.gdppc kofgi polity popdens cbd i.country

global altX c.gdppc##c.gdppc kofgi popdens cbd i.country



**************************************
** 1.1 Main Regression ***************
****** Table 1 and Panel 1, Figure 2 *
**************************************

*** 1.1.1 Table 1

eststo clear

eststo m1_1: qui xtpcse papcnt fdistock, correlation(ar1) pairwise

eststo m1_2: qui xtpcse papcnt fdistock i.country, correlation(ar1) pairwise

eststo m1_3: qui xtpcse papcnt fdistock i.country i.year, correlation(ar1)

eststo m1_4: qui xtpcse papcnt fdistock $X diffusion time, correlation(ar1) pairwise

eststo m1_5: qui xtpcse papcnt c.fdistock##c.fdistock, correlation(ar1) pairwise

eststo m1_6: qui xtpcse papcnt c.fdistock##c.fdistock i.country, correlation(ar1) pairwise

eststo m1_7: qui xtpcse papcnt c.fdistock##c.fdistock i.country i.year, correlation(ar1)

eststo m1_8: qui xtpcse papcnt c.fdistock##c.fdistock $X diffusion time, correlation(ar1) pairwise

test fdistock c.fdistock#c.fdistock /// joint significance test


global esttab_sty /*
*/ label se collabels(none) mlabels(none) stats(N rmse, labels("Obs." "RMSE") fmt(%9.0fc 3))


esttab m1_1 m1_2 m1_3 m1_4 m1_5 m1_6 m1_7 m1_8, $esttab_sty /*
*/ title("Table 1: Positive Effect of FDI Stock on Protected Areas (\% of Territory)") /*
*/ order(fdistock c.fdistock#c.fdistock) coef(c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared") /*
*/ indicate("Country fixed effects = *.country" "Year fixed effects = *.year") /*
*/ drop(_cons)


*** 1.1.2 Panel 1, Figure 2 (marginal effects plot)

generate rug = "|"

generate where_rug = 0

global marginsplot_details /*
*/ level(95) /*
*/ recast(line) recastci(rline) ciopts(lpattern(dash)) legend(off) /*
*/ addplot(scatter where_rug fdistock, ms(none) blcolor(gray) mlcolor(gray) lcolor(gray) mlabel(rug) mlabpos(0)) /*
*/ scheme(lean2) ytitle("") 

qui margins, at(fdistock = (0.00 (0.05) 10.00))

marginsplot, $marginsplot_details /*
*/ name("m1") xscale(off) /*
*/ title("Panel 1: Main Model (Column 8, Table 1)", size(medsmall)) subtitle("(Obs. = 1,789)", size(small))



********************************************
** 1.2 Regression without Advanced Economies
****** Table A2
******************************************** 

*** 1.2.1 Table A2

eststo s2_subsample_1: qui xtpcse papcnt fdistock $X diffusion time if oecd == 0, correlation(ar1) pairwise

eststo s2_subsample_2: qui xtpcse papcnt c.fdistock##c.fdistock $X diffusion time if oecd == 0, correlation(ar1) pairwise

esttab s2_subsample_1 s2_subsample_2, $esttab_sty /*
*/ title("Table A2: Positive Effect of FDI Stock on Protected Areas, with Advanced Economies Excluded") /*
*/ order(fdistock c.fdistock#c.fdistock) coef(c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared") /*
*/ drop(_cons *country)


*** 1.2.2 Panel 2, Figure 2 (marginal effects plot)

qui margins, at(fdistock = (0.00 (0.05) 10.00))

marginsplot, $marginsplot_details /*
*/ name("s2") xscale(off) title("Panel 2: Advanced Economies Excluded (Table A2)", size(medsmall)) subtitle("(Obs. = 1,135)", size(small))



***************************************
** 1.3 Leave-One-Country Out Regression
****** Visualized by 4-misc.R
***************************************

forvalues i = 1/60 { // number of countries
	eststo loco`i': qui xtpcse papcnt c.fdistock##c.fdistock $X diffusion time if country != `i', correlation(ar1) pairwise
}
esttab loco* using "3-loco-estimates.csv", replace se plain keep(fdistock c.fdistock#c.fdistock)



*************************************
** 1.4 FDI Lagged t-1
****** Table A3 and Panel 3, Figure 2
*************************************

*** 1.4.1 Table A3

eststo s3_laggedX_t1_1: qui xtpcse papcnt L1.fdistock L1.c.gdppc##L1.c.gdppc L1.kofgi L1.polity L1.popdens cbd i.country L1.diffusion time, correlation(ar1) pairwise

eststo s3_laggedX_t1_2: qui xtpcse papcnt L1.c.fdistock##L1.c.fdistock L1.c.gdppc##L1.c.gdppc L1.kofgi L1.polity L1.popdens cbd i.country L1.diffusion time, correlation(ar1) pairwise

esttab s3_laggedX_t1_1 s3_laggedX_t1_2, $esttab_sty /*
*/ title("Table A3: Positive Effect of FDI Stock on Protected Areas, with FDI Stock Lagged t-1") /*
*/ order(L.fdistock cL.fdistock#cL.fdistock) /*
*/ coef(L.fdistock "FDI stock" cL.fdistock#cL.fdistock "FDI stock, squared" L.gdppc "GDP per capita" cL.gdppc#cL.gdppc "GDP per capita, squared" L.kofgi "KOF Globalization Index" L.polity "Polity score" L.popdens "Population density" cbd "Post-CBD" L.diffusion "Regional diffusion" time "Time trend") /*
*/ drop(_cons *country)


*** 1.4.2 Panel 3, Figure 2 (marginal effects plot)

qui margins, at(L1.fdistock = (0.00 (0.05) 10.00))

marginsplot, $marginsplot_details /*
*/ name("s3") xtitle("FDI stock", margin(0 0 0 5)) title("Panel 3: FDI Stock Lagged {it: t{&minus}1} (Table A3)", size(medsmall)) subtitle("(Obs. = 1,789)", size(small))



*********************
** 1.5 FDI Lagged t-2
****** Table A4
*********************

eststo s4_laggedX_t2_1: qui xtpcse papcnt L2.fdistock L2.c.gdppc##L2.c.gdppc L2.kofgi L2.polity L2.popdens cbd i.country L2.diffusion time, correlation(ar1) pairwise

eststo s4_laggedX_t2_2: qui xtpcse papcnt L2.c.fdistock##L2.c.fdistock L2.c.gdppc##L2.c.gdppc L2.kofgi L2.polity L2.popdens cbd i.country L2.diffusion time, correlation(ar1) pairwise

esttab s4_laggedX_t2_1 s4_laggedX_t2_2, $esttab_sty /*
*/ title("Table A4: Positive Effect of FDI Stock on Protected Areas, with FDI Stock Lagged t-2") /*
*/ order(L2.fdistock cL2.fdistock#cL2.fdistock) /*
*/ coef(L2.fdistock "FDI stock" cL2.fdistock#cL2.fdistock "FDI stock, squared" L2.gdppc "GDP per capita" cL2.gdppc#cL2.gdppc "GDP per capita, squared" L2.kofgi "KOF Globalization Index" L2.polity "Polity score" L2.popdens "Population density" cbd "Post-CBD" L2.diffusion "Regional diffusion" time "Time trend") /*
*/ drop(_cons *country)



*********************
** 1.6 FDI Lagged t-3
****** Table A5
*********************

eststo s5_laggedX_t3_1: qui xtpcse papcnt L3.fdistock L3.c.gdppc##L3.c.gdppc L3.kofgi L3.polity L3.popdens cbd i.country L3.diffusion time, correlation(ar1) pairwise

eststo s5_laggedX_t3_2: qui xtpcse papcnt L3.c.fdistock##L3.c.fdistock L3.c.gdppc##L3.c.gdppc L3.kofgi L3.polity L3.popdens cbd i.country L3.diffusion time, correlation(ar1) pairwise

esttab s5_laggedX_t3_1 s5_laggedX_t3_2, $esttab_sty /*
*/ title("Table A5: Positive Effect of FDI Stock on Protected Areas, with FDI Stock Lagged t-3") /*
*/ order(L3.fdistock cL3.fdistock#cL3.fdistock) /*
*/ coef(L3.fdistock "FDI stock" cL3.fdistock#cL3.fdistock "FDI stock, squared" L3.gdppc "GDP per capita" cL3.gdppc#cL3.gdppc "GDP per capita, squared" L3.kofgi "KOF Globalization Index" L3.polity "Polity score" L3.popdens "Population density" cbd "Post-CBD" L3.diffusion "Regional diffusion" time "Time trend") /*
*/ drop(_cons *country)



*************************************
** 1.7 Lagged Dependent Variable
****** Table A6 and Panel 4, Figure 2
*************************************

*** 1.7.1 Table A6

gen ldv = L5.papcnt // L5 since FDI already 5-year moving-averged 

eststo s6_ldv_1: qui xtpcse papcnt ldv fdistock $X diffusion time, correlation(independent)

eststo s6_ldv_2: qui xtpcse papcnt ldv c.fdistock##c.fdistock $X diffusion time, correlation(independent)

esttab s6_ldv_1 s6_ldv_2, $esttab_sty /*
*/ title("Table A6: Positive Effect of FDI Stock on Protected Areas, with Lagged Dependent Variable Included") /*
*/ order(fdistock c.fdistock#c.fdistock) coef(c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared") /*
*/ drop(_cons *country)


*** 1.7.2 Panel 4, Figure 2 (marginal effects plot)

qui margins, at(fdistock = (0.00 (0.05) 10.00))

marginsplot, $marginsplot_details /*
*/ name("s6") xtitle("FDI stock", margin(0 0 0 5)) title("Panel 4: Lagged Dependent Variable Included (Table A6)", size(medsmall)) subtitle("(Obs. = 1,616)", size(small))


graph combine m1 s2 s3 s6, /*
*/ l1title("Protected Areas (% of Territory)", margin(0 7.5 0 0) size(vsmall)) rows(2) xcommon ycommon scheme(lean2) ysize(10) xsize(12) iscale(0.60)

graph export "5-figures/main-2-marginsplot.png", width(3600) height(3200) replace



******************************************************************
** 1.8 Full Specification with Both Country and Year Fixed Effects
****** Table A7
******************************************************************

eststo s7_1: qui xtpcse papcnt fdistock $X diffusion i.country i.year, correlation(ar1)

eststo s7_2: qui xtpcse papcnt c.fdistock##c.fdistock $X diffusion i.country i.year, correlation(ar1)

esttab s7_1 s7_2, $esttab_sty /*
*/ title("Table A7: Positive Effect of FDI Stock on Protected Areas, with Full Specification and Both Country and Year Fixed Effects Included") /*
*/ order(fdistock c.fdistock#c.fdistock) /*
*/ coef(c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared") /*
*/ drop(_cons *.country *.year)



**************************************
** 1.9 FDI Flows as Dependent Variable
****** Table A8
**************************************

eststo s8_reverse_flows_1: qui xtreg fdiflow L2.papcnt L2.gdppc L2.kofgi L2.polity L2.popdens time, fe vce(cluster country)

eststo s8_reverse_flows_2: qui xtreg fdiflow L.papcnt L.gdppc L.kofgi L.polity L.popdens time, fe vce(cluster country)

eststo s8_reverse_flows_3: qui xtreg fdiflow papcnt gdppc kofgi polity popdens time, fe vce(cluster country)

eststo s8_reverse_flows_4: qui xtreg fdiflow F.papcnt F.gdppc F.kofgi F.polity F.popdens time, fe vce(cluster country)

eststo s8_reverse_flows_5: qui xtreg fdiflow F2.papcnt F2.gdppc F2.kofgi F2.polity F2.popdens time, fe vce(cluster country)

esttab s8_reverse_flows_1 s8_reverse_flows_2 s8_reverse_flows_3 s8_reverse_flows_4 s8_reverse_flows_5, $esttab_sty /*
*/ title("Null Effect of Protected Areas (\% of Territory) on FDI Flows, with the Right-hand Side Variables Lagged/Leading") /*
*/ rename(L2.papcnt "Protected areas" L.papcnt "Protected areas" papcnt "Protected areas" F.papcnt "Protected areas" F2.papcnt "Protected areas" /*
*/ L2.gdppc "GDP per capita" L.gdppc "GDP per capita" gdppc "GDP per capita" F.gdppc "GDP per capita" F2.gdppc "GDP per capita" /*
*/ L2.kofgi "KOF Globalization Index" L.kofgi "KOF Globalization Index" kofgi "KOF Globalization Index" F.kofgi "KOF Globalization Index" F2.kofgi "KOF Globalization Index" /*
*/ L2.polity "Polity score" L.polity "Polity score" polity "Polity score" F.polity "Polity score" F2.polity "Polity score" /*
*/ L2.popdens "Population density" L.popdens "Population density" popdens "Population density" F.popdens "Population density" F2.popdens "Population density")



**********************
** 1.10 GMM Estimation
****** Table A9
**********************

gen gdp_inter = gdppc*gdppc

gen fdi_inter = fdistock*fdistock

xtabond2 papcnt l.papcnt fdistock fdi_inter gdppc gdp_inter kofgi polity popdens cbd diffusion time,  gmm (l.papcnt fdi_inter fdi_inter, lag(1 2) collapse) iv(kofgi popdens cbd time polity i.country) robust 



******************************************
** 1.11 More/Alternative Control Variables
******* Table A10
******************************************

*** 1.10.1 V-Dem regime type measure (replacing the Polity one)
*** Column 1–2, Table A9

eststo s10_1_vdem_1: qui xtpcse papcnt fdistock $altX v2x_polyarchy diffusion time, correlation(ar1) pairwise
eststo s10_2_vdem_2: qui xtpcse papcnt c.fdistock##c.fdistock $altX v2x_polyarchy diffusion time, correlation(ar1) pairwise


*** 1.10.2 Corruption as an additional control
*** Column 3–4, Table A9

eststo s10_3_corr_1: qui xtpcse papcnt fdistock $X v2x_corr diffusion time, correlation(ar1) pairwise
eststo s10_4_corr_2: qui xtpcse papcnt c.fdistock##c.fdistock $X v2x_corr diffusion time, correlation(ar1) pairwise


*** 1.10.3 Resources rents as an additional control
*** Column 5–6, Table A9

eststo s10_5_rents_1: qui xtpcse papcnt fdistock $X resources_rents diffusion time, correlation(ar1) pairwise
eststo s10_6_rents_2: qui xtpcse papcnt c.fdistock##c.fdistock $X resources_rents diffusion time, correlation(ar1) pairwise


*** 1.10.4 State capacity as an additional control
*** Column 7–8, Table A9

eststo s10_7_capacity_1: qui xtpcse papcnt fdistock $X state_capacity diffusion time, correlation(ar1) pairwise
eststo s10_8_capacity_2: qui xtpcse papcnt c.fdistock##c.fdistock $X state_capacity diffusion time, correlation(ar1) pairwise


*** 1.10.5 Single regression table including all the above

esttab s10_1_vdem_1 s10_2_vdem_2 s10_3_corr_1 s10_4_corr_2 s10_5_rents_1 s10_6_rents_2 s10_7_capacity_1 s10_8_capacity_2, $esttab_sty /*
*/ title("Positive Effect of FDI Stock on Protected Areas, with Alternative/Additional Control Variables") /*
*/ order(fdistock c.fdistock#c.fdistock) /*
*/ coef(c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared") /*
*/ drop(_cons *.country)



*************************
* 2 ADDITIONAL ANALYSIS *
*************************

*** Null Effect of PA on FDI Expropriation
*** Table 2

eststo m2_exp_1: qui logit exprop L.papcnt polity c.fdistock##c.fdistock c.gdppc##c.gdppc history c.time##c.time##c.time if year != 1984, cluster(country)

eststo m2_exp_2: qui logit exprop papcnt polity c.fdistock##c.fdistock c.gdppc##c.gdppc history c.time##c.time##c.time if year != 1984, cluster(country)

eststo m2_exp_3: qui logit exprop F.papcnt polity c.fdistock##c.fdistock c.gdppc##c.gdppc history c.time##c.time##c.time if year != 1984, cluster(country)

esttab m2_exp_1 m2_exp_2 m2_exp_3, label se /*
*/ title("Null Effect of Protected Areas (% of Territory) on the Occurrence of FDI Expropriation") /*
*/ coef(papcnt "Protected areas" L.papcnt "Protected areas (t-1)" F.papcnt "Protected areas (t+1)" /*
*/ c.fdistock#c.fdistock "FDI stock, squared" c.gdppc#c.gdppc "GDP per capita, squared" /*
*/ time "Time" c.time#c.time "Time, squared" c.time#c.time#c.time "Time, cubed") /*
*/ star(* 0.10 ** 0.05 *** 0.01) /* /// consistent with Esberg and Perlman (2023)
*/ cells((b(star fmt(%9.3f))) (se(fmt(%9.3f)par))) /*
*/ stats(N ll, labels("Obs." "Log Likelihood") fmt(%9.0fc 3)) /*
*/ collabels(none) mlabels(none) /*
*/ drop(_cons)



******************
* END OF DO FILE *
******************
